home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst19.cpp < prev    next >
C/C++ Source or Header  |  1996-03-24  |  2KB  |  98 lines

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST19
  4.  
  5. // this sample demonstrates using an abstract base class
  6. // and using mixin inheritance
  7.  
  8. // Simple stream I/O is used to interact with the user.
  9. #include "oofile.hpp"
  10.  
  11. class dbSomeFields
  12. {
  13. public:
  14.     dbChar Recipient;
  15.     dbSomeFields() :
  16.         Recipient(80, "Recipient")
  17.     {};
  18. };
  19.  
  20.  
  21. DECLARE_ABSTRACT_CLASS(dbFileBase)
  22. public:
  23.     dbChar        FileName;
  24.     dbFileBase() : FileName(255, "File Name") {};
  25.     virtual void FormattedName(ostream&)=0;
  26. };
  27.  
  28.  
  29. class dbIncoming : public dbFileBase
  30. {
  31. public:
  32. // as we inherit from other than dbTable,
  33. // must use the following macro instead of DECLARE_CLASS
  34.     OOFILE_METHODS(dbIncoming)
  35.     virtual void FormattedName(ostream&);
  36.     dbIncoming() : dbFileBase() {};
  37. };
  38.  
  39.  
  40. class dbOutgoing : public dbFileBase, public dbSomeFields
  41. {
  42. public:
  43. // as we use multiple inheritance, must use the following macro instead of DECLARE_CLASS
  44.     OOFILE_METHODS(dbOutgoing)
  45.     virtual void FormattedName(ostream&);
  46.     dbOutgoing() : dbFileBase(), dbSomeFields() {};
  47. };
  48.  
  49.  
  50. void 
  51. dbIncoming::FormattedName(ostream& os)
  52. {
  53.     os << FileName << endl;
  54. }
  55.  
  56.  
  57. void 
  58. dbOutgoing::FormattedName(ostream& os)
  59. {
  60.     os << FileName << " sent to " << Recipient << endl;
  61. }
  62.  
  63.  
  64. int main()
  65. {
  66.     dbConnect_ctree       theDB;
  67.     dbIncoming             Incoming;
  68.     dbOutgoing            Outgoing;
  69.  
  70.     cout << "OOFILE Validation Suite - Test 19\n"
  71.          << "Simple test to demonstrate inheritance" << endl;
  72.  
  73.     if (dbConnect::fileExists("ooftst19.db")) {
  74.         theDB.openConnection("ooftst19.db");
  75.     }
  76.     else {
  77.         theDB.newConnection("ooftst19.db");
  78.         Incoming.newRecord();
  79.         Incoming.FileName = "An Incoming File";
  80.         Incoming.saveRecord();
  81.         
  82.         Outgoing.newRecord();
  83.         Outgoing.FileName = "An Outgoing File";
  84.         Outgoing.Recipient = "XXX";
  85.         Outgoing.saveRecord();
  86.         
  87.     }
  88.  
  89.     cout << "Invoking a virtual function on each in turn" << endl;
  90.     Incoming.FormattedName(cout);
  91.     Outgoing.FormattedName(cout);
  92.  
  93.     cout << endl << "Dumping entire database" << theDB;
  94.     
  95.     cout << "Test Completed" << endl;
  96.  
  97.     return EXIT_SUCCESS;
  98. }